---
title: "PoliticalAdsCode"
date: '2023-08-04'
output:
  html_document: default
  pdf_document: default
---

```{r setup, message=FALSE}
knitr::opts_chunk$set(include = T, message = F, cache.lazy = T, warning=F,fig.width=12, fig.height=8)

library(cowplot)
library(descr)
library(readr)
library(magick)
library(dplyr)
library(ggeffects)
library(magrittr)
library(grid)
library(kableExtra)
library(stringr)
library(gridExtra)
library(knitr)
library(ggplot2)
library(gtable)
library(labelled)
library(haven)
library(gmodels)
library(png)
library(tidyverse)
library(cjoint)
library(stargazer)
library(Hmisc)
library(sjPlot)
library(labelled)
library(haven)
library(png)
library(magicfor)    
library(magicfor)  
library(fastDummies)
library(lme4)
library(coefplot)
library(pBrackets)
library(estimatr)
library(ggtext)
library(texreg)


####################
#Load data
####################

PATH=''
#to extract cjoint data for plots, I modify their source code
source(paste0(PATH, 'plot_amce.R'))

#conjoint experiment data
cj <- read.csv(file = paste0(PATH,'Data/Conjoint/CJ.csv'), header = TRUE,
               stringsAsFactors = T)





cj$GENDER[cj$GENDER==1]<-'Male'
cj$GENDER[cj$GENDER==2]<-'Female'
cj$GENDER<-factor(cj$GENDER)


cj_male<-cj[cj$GENDER=='Male',]
cj_female<-cj[cj$GENDER=='Female',]

#Real ads means data
dat <- read.csv(paste0(PATH,'Data/Real/data.csv')) 
datb <- read.csv(paste0(PATH,'Data/Real/datb.csv'))
datc <- read.csv(paste0(PATH,'Data/Real/datc.csv'))

#Real ads lm data
orig <- read.csv(paste0(PATH,'Data/Real/original.csv'))
redo <- read.csv(paste0(PATH,'Data/Real/correction.csv'))
pooled <- read.csv(paste0(PATH,'Data/Real/pooled.csv'))

pooled_gender <- read.csv(paste0(PATH,'Data/Real/pooled_gender.csv'))



####################
#global custom theme
####################

label.baseline = TRUE
text.size = 30
text.color = "black"
point.size = 0.5
dodge.size = 0.9
font.family=NULL 
theme_bw1 <- function(base_size = text.size, base_family = "") {
  theme_bw(base_size = base_size, base_family = base_family 
  ) %+replace% 
    theme(axis.text.x = 
            element_text(size = base_size *  0.9, 
                         colour = text.color, hjust = 0.5,
                         vjust = 1),  
          axis.text.y = element_text(size = base_size, 
                                     colour = text.color,
                                     hjust = 0, vjust = 0.5,
                                     family = font.family), 
          axis.title.y = element_text(size = base_size, 
                                      angle = 180, vjust = 0.01,
                                      hjust = 0.1, 
                                      family = font.family), 
          
          plot.title = element_text(face = "bold", 
                                    family = font.family),
          axis.ticks = element_blank(), 
          
          legend.background = element_blank(), 
          
          legend.key = element_blank(),
          panel.background = element_blank(), 
          panel.border = element_blank(), 
          strip.background = element_blank(), 
          
          
          plot.background = element_blank(), complete = TRUE,
          panel.grid.minor =   element_blank(),
          panel.grid.major =  element_line(colour = "grey87",size=0.5))
}
theme_set(theme_bw1())

```

#Manuscript Replication

## Conjoint Experiment

summary statistics. 

```{r}
# Create a grouping variable based on columns 102 to 105
cj$group <- apply(cj[, 102:105], 1, paste, collapse = "_")


# Calculate mean, standard deviation, and N for each group
summary_stats <- cj %>%
  group_by(group) %>%
  summarise(
    mean_dv = mean(dv1, na.rm = TRUE),         # Mean of dv
    sd_dv = sd(dv, na.rm = TRUE),             # Standard deviation of dv
    N = n()                                   # Count of observations (Ns)
  )

# Display the results
print(summary_stats)


```

First, define baselines. Conjoint experiments need baselines defined separately for unconditional and interacted. 
```{r baselines}

baselines <- list()
baselines$sourceType <- "Company"
baselines$sourceOrient <- "Pro-environment"
baselines$messageStrength <- "Weak"
baselines$messageOrient <- "Pro-environment"
baselines$image <- "Landscape"
baselines$pid <- 'Republican'
# baselines$GENDER <- 'Male'


bases <- list()
bases$image <- 'Landscape'
bases$messageOrient <- 'Pro-environment'
bases$messageStrength <- 'Weak'
bases$sourceOrient <- 'Pro-environment'
bases$sourceType <- 'Company'

```

### Unconditional effect
```{r Unconditional}

#Unconditional amce
unconditional <- amce(dv1 ~ image  + messageOrient + messageStrength + sourceOrient + sourceType, respondent.id= 'CaseId', cluster=TRUE,  weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)


#lm object to be overwritten
uncon <- summary(lm(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType , data=cj, weights=WEIGHT))

#overwrite lm object with cjoint data
uncon$coefficients[2:11,c('Estimate','Std. Error','Pr(>|t|)')] <- rbind(cbind(summary(unconditional)$amce[,c('Estimate')],summary(unconditional)$amce[,c('Std. Err')],summary(unconditional)$amce[,c('Pr(>|z|)')]))

```


### Interacted effect
```{r Interacted ,out.width='75%', fig.align='center',fig.show = 'hide'}
################
# PRIOR
################


################
#message X priors
################

mesxprior <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + priors + messageOrient*priors, cluster=TRUE, respondent.id="CaseId", respondent.varying= 'priors', weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)

################
#source X priors
################

sourcexprior <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + priors + sourceOrient*priors, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'priors', na.ignore=T)

################################
#new model w both interactions
################################

sourcexpriorxmess <- amce(dv1 ~   image  + messageOrient + messageStrength + sourceOrient + sourceType  + priors +  messageOrient*priors + sourceOrient*priors, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'priors', na.ignore=T)

####################################################
#edited cj source code to extract data
####################################################

plt1(mesxprior,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datM <- plotdata#extract output
plt1(sourcexprior,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datS <- plotdata
plt1(sourcexpriorxmess,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datMS <- plotdata


################
# GENDER
################


################
#message X GENDER
################

mesxGENDER <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + GENDER + messageOrient*GENDER, cluster=TRUE, respondent.id="CaseId", respondent.varying= 'GENDER', weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)

################
#source X GENDER
################

sourcexGENDER <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + GENDER + sourceOrient*GENDER, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'GENDER', na.ignore=T)

################################
#new model w both interactions
################################

sourcexGENDERxmess <- amce(dv1 ~   image  + messageOrient + messageStrength + sourceOrient + sourceType  + GENDER +  messageOrient*GENDER + sourceOrient*GENDER, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'GENDER', na.ignore=T)

####################################################
#edited cj source code to extract data
####################################################

plt1(mesxGENDER,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datMgender <- plotdata#extract output
plt1(sourcexGENDER,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datSgender <- plotdata
plt1(sourcexGENDERxmess,plot.display='interaction',colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'))
datMSgender <- plotdata

```



### Figure 2 

*Effect of advertisement's attributes on perception of ad's politicalness (Average Marginal Component Effects)*

```{r f2,out.width='75%', fig.align='center'}

unconditional <- amce(dv1 ~ image  + messageOrient + messageStrength + sourceOrient + sourceType  , respondent.id= 'CaseId', cluster=TRUE,  weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)
summary(unconditional)

nums <- 7:20

plt1(unconditional, 
     colors=c("paleturquoise4","lightpink3","sienna4", 'navajowhite3'),
     xlab="Change in \n Pr(Ad considered more political)", 
     attribute.names= c('Images','Message orientation',
                        'Message strength','Source orientation',
                        'Source type'),
     point.size=1.5, 
     plot.theme=theme_set(theme_bw1())+
       theme(axis.text.y = element_text(size=rev(c(30,24 ,30 , 30, 24, 30 ,30,30 ,24,30,30, 24, 30, 30))))+
       theme(axis.text.y = element_text(face=rev(
         c("bold","italic", "plain","bold", 'italic',
           'plain','plain','bold', "italic","plain",
           'bold','italic','plain','plain'))))+
       theme(axis.text.x = element_text(size=24))+
       theme(legend.position = 'none'))

```


### Figure 3 

*Source and message interaction*

```{r f3,out.width='75%', fig.align='center'}

d <- rbind(datM,datS)
d$group[d$group == "<NA>"] <- NA
d$facet <- factor(d$facet,levels=unique(d$facet))
d$var <- factor(d$var, levels=c(levels(d$var)[4:6],levels(d$var)[1:3]))
d$prior[d$facet=="Conditional on\npriors = Pro-development"]<- 'Pro-development'
d$prior[d$facet==levels(d$facet)[2]]<- 'Pro-environment'
d$`Prior attitudes:` <- d$prior

group.order=c('messageOrient','sourceOrient')
if (!is.null(group.order)){
  
  n.row <- length(unique(as.character(d$var)))
  order.var <- vector("character", length = n.row)
  
  i <- 1
  while (i<n.row){
    for (j in group.order){
      order.var[i] <- unique(as.character(d$var[d$var==gsub(" ","",j)]))
      i <- i+1
      temp.d <- d
      temp.d$group <- gsub(" ","",temp.d$group)
      temp.d <- subset(temp.d, group==gsub(" ","",j))
      
      temp.var <- unique((as.character(temp.d$var)))
      order.var[i:(i+length(temp.var)-1)] <- temp.var
      i <- i+length(temp.var)
    }
  }
  order.var <- rev(order.var)
  
  order.df <- data.frame(order.var, 1:length(order.var))
  colnames(order.df) <- c("var", "order")
  
  d$var <- factor(d$var, levels=order.var)
  
  d <- merge(d, order.df, by.x="var", by.y="var", suffixes=c("",""))
  
}


labels= c('Message orientation:','  (Baseline: Pro-environment) ','  Pro-development ','Source orientation:','  (Baseline: Pro-environment)', '  Pro-development')
col <-c("paleturquoise4","lightpink3")

summary(d)
p=ggplot(d, aes(y = pe, x = var, color = `Prior attitudes:`, shape=`Prior attitudes:`))+
  theme_set(theme_bw1())+
  geom_hline(yintercept = 0, size = 1, colour = "gray", 
                   linetype = "dashed") +
  geom_pointrange(aes(y=pe,ymin = lower, ymax = upper, color = `Prior attitudes:`, shape=`Prior attitudes:`), 
                  position=position_dodge(width = -.8),
                  size = 1.5)+
  xlab("")+
  ylab('Change in \n Pr(Ad considered more political)')+
  ylim(-.13,.13)+
  coord_flip()


p +scale_x_discrete(labels=rev(labels))+
  theme(axis.text.y = element_text(face=rev(c("bold","italic", "plain","bold", 'italic','plain'))))+  
  theme(axis.text.y = element_text(size=rev(c(30,24 ,30 , 30, 24, 30))))+
  theme(legend.position = 'bottom',legend.justification = "left")+
  scale_color_manual(values=c("paleturquoise4","lightpink3"), 
                    guide="legend")+
  theme(axis.text.x= element_text( size = 20),legend.text=element_text(size=20))+
  theme(axis.title.x = element_text(size=24))+
  theme(legend.title = element_text(size=22, face = 'bold'))+
  theme(plot.margin = margin(1,2,0,0, "cm"))



```

### Gender interact
```{r}
d <- rbind(datMgender,datSgender)
d$group[d$group == "<NA>"] <- NA
d$facet <- factor(d$facet,levels=unique(d$facet))
d$var <- factor(d$var, levels=c(levels(d$var)[4:6],levels(d$var)[1:3]))
d$GENDER[d$facet=="Conditional on\nGENDER = Female"]<- 'Female'
d$GENDER[d$facet=='Conditional on\nGENDER = Male']<- 'Male'
d$`Gender:` <- d$GENDER

group.order=c('messageOrient','sourceOrient')
if (!is.null(group.order)){
  
  n.row <- length(unique(as.character(d$var)))
  order.var <- vector("character", length = n.row)
  
  i <- 1
  while (i<n.row){
    for (j in group.order){
      order.var[i] <- unique(as.character(d$var[d$var==gsub(" ","",j)]))
      i <- i+1
      temp.d <- d
      temp.d$group <- gsub(" ","",temp.d$group)
      temp.d <- subset(temp.d, group==gsub(" ","",j))
      
      temp.var <- unique((as.character(temp.d$var)))
      order.var[i:(i+length(temp.var)-1)] <- temp.var
      i <- i+length(temp.var)
    }
  }
  order.var <- rev(order.var)
  
  order.df <- data.frame(order.var, 1:length(order.var))
  colnames(order.df) <- c("var", "order")
  
  d$var <- factor(d$var, levels=order.var)
  
  d <- merge(d, order.df, by.x="var", by.y="var", suffixes=c("",""))
  
}


labels= c('Message orientation:','  (Baseline: Pro-environment) ','  Pro-development ','Source orientation:','  (Baseline: Pro-environment)', '  Pro-development')
col <-c("DarkOrange3","SeaGreen4")

summary(d)
p=ggplot(d, aes(y = pe, x = var, color = `Gender:`, shape=`Gender:`))+
  theme_set(theme_bw1())+
  geom_hline(yintercept = 0, size = 1, colour = "gray", 
                   linetype = "dashed") +
  geom_pointrange(aes(y=pe,ymin = lower, ymax = upper, color = `Gender:`, shape=`Gender:`), 
                  position=position_dodge(width = -.8),
                  size = 1.5)+
  xlab("")+
  ylab('Change in \n Pr(Ad considered more political)')+
  ylim(-.13,.13)+
  coord_flip()


p +scale_x_discrete(labels=rev(labels))+
  theme(axis.text.y = element_text(face=rev(c("bold","italic", "plain","bold", 'italic','plain'))))+  
  theme(axis.text.y = element_text(size=rev(c(30,24 ,30 , 30, 24, 30))))+
  theme(legend.position = 'bottom',legend.justification = "left")+
  scale_color_manual(values=c("DarkOrange3","SeaGreen4"), 
                    guide="legend")+
  theme(axis.text.x= element_text( size = 20),legend.text=element_text(size=20))+
  theme(axis.title.x = element_text(size=24))+
  theme(legend.title = element_text(size=22, face = 'bold'))+
  theme(plot.margin = margin(1,2,0,0, "cm"))


```


## Real advertisments


### Figure 4 

*Average perceived politicalness of political ads by source and message strength*

```{r f4,out.width='75%', fig.align='center'}


datc = datc[,-1]
#reorder level for display
datc$Ad = factor(datc$Ad, levels=rev(c("Biden","Trump","Power", "Sierra",                             'Patagonia',"Exxon","MSC","Colgate")))
datc$`Political Content` <- datc$political

#plots
f4 <- ggplot(datc, aes(y = Estimate, x = Ad , color=`Political Content`  ))+
  geom_pointrange(aes(y = Estimate,ymin = `CI.lower`, 
                      ymax = `CI.upper`),
                  position = position_dodge(width = -.6),
                  size = 1) +
  coord_flip() + 
  ylab("")+ xlab("")+
   theme(panel.spacing.x = unit(27, "mm"),
        axis.text.x=element_text(angle=0,
                                 hjust=0.5,vjust=.5))+
  theme(axis.text.y = element_text(face=rev(c("bold","bold",
                                              "italic","italic",
                                              'plain','plain','plain','plain'))))


f4+theme(text=element_text(size=20)) + scale_color_manual(values =  c("sienna4", 'navajowhite3'), name = "")+ geom_hline( yintercept = 0, colour = "gray", size = 1, lty= 'dashed')+
  theme(plot.margin = unit(c(1,1,2,3), "cm"))+
  theme(axis.text.y= element_text( size = 20),axis.text.x= element_text( size = 18),legend.text=element_text(size=20))

# ggsave(paste0(PATH,"Output/Plots/","mean-pool-plot.pdf"), width = 12, height = 9, units = "in")


# #May add these grids and labels in plot view if you change your plot region to 12x9 
# grid.brackets(100, 172,  100, 91, type=4, ticks=NA,h =.05)
# grid.brackets(100, 325,  100, 245, type=4, ticks=NA,h =.05)
# grid.brackets(100, 490,  100, 405, type=4,ticks=NA,h =.008, col ='gray')
# grid.brackets(100, 650,  100, 560, type=4,ticks=NA,h =.008, col ='gray')
# grid.brackets(100, 655,  100, 400, type=4,ticks=NA,h =.05)
# 
# 
# 
# grid.text(x=unit(33, 'native'), y=unit(100, 'native'), label='Politicians', rot=90,
#           gp = gpar(fontsize = 18, fontface = "bold") )
# grid.text(x=unit(33, 'native'), y=unit(225, 'native'), label='Organizations', rot=90,
#           gp = gpar(fontsize = 18, fontface = "italic") )
# grid.text(x=unit(33, 'native'), y=unit(400, 'native'), label='Companies', rot=90,
#           gp = gpar(fontsize = 18) )
# grid.text(x=unit(62, 'native'), y=unit(335, 'native'), label='Political', rot=90,
#           gp = gpar(fontsize = 13))
# 
# grid.text(x=unit(62, 'native'), y=unit(450, 'native'), label='Non-political', rot=90,
#           gp = gpar(fontsize = 13))

```


# Appendix replication


### Figure D1

*Mean politicalness scores for the validation test of the conjoint experiment* 

```{r fd1}


pilot <- read.csv(paste0(PATH,'Data/Pilot/pilot2_RmAt.csv'))

ads <-pilot[,1:6]
colnames(ads)<-paste0('message',1:6)

for(i in 1:ncol(ads)){
  for(j in  1:nrow(ads)){
    ads[j,i][ads[j,i]==""] <- NA}
  ads[,i] <- factor(ads[,i], levels=(c('5','4','3','2','1')))
}

vals <- data.frame(matrix(ncol=4,nrow=6,NA))
colnames(vals) <- c('Estimate','Lower 95 CI','Upper 95 CI','Standard Err.')

for(i in 1:ncol(ads)){
  vals[i,] <- ci(as.numeric(ads[,i]), na.rm=T)
}

vals$Ad <- c( "Strong pro-development","Strong pro-environment", "Moderate pro-development","Moderate pro-environment", "Weak pro-development", "Weak pro-environment"  )
vals$Ad = factor(vals$Ad, levels=rev( c( "Strong pro-development","Strong pro-environment", "Moderate pro-development","Moderate pro-environment", "Weak pro-development", "Weak pro-environment"  )))
conjoint <- vals
#plots
f1<- ggplot(vals, aes(y = Estimate, x = Ad  ))+
  geom_pointrange(aes(y = Estimate,ymin = `Lower 95 CI`, 
                      ymax = `Upper 95 CI`),
                  size = 1, color = "sienna4") +
  coord_flip() + 
  ylim(1,4)+  xlab("")+ 
  ylab("")+ 
  scale_y_continuous(limits = c(1,5),
                     labels=c('Not \n political \n (1)',
                              '',
                              '\n\n (3)',
                              '',
                              'Extremely \n political \n (5)'))+ 
  theme(panel.spacing.x = unit(27, "mm"),
        axis.text.x=element_text(angle=0,
                                 hjust=0.5,vjust=.5))#+
# theme(axis.text.y = element_text(face=rev(c("bold","bold",
#                                             "italic","italic",
#                                             'plain','plain','plain','plain'))))

f1+theme(text=element_text(size=20)) + scale_color_manual(values =  c("sienna4", 'navajowhite3'), name = "")+ geom_hline( yintercept = 0, colour = "gray", size = 1, lty= 'dashed')+
  theme(plot.margin = unit(c(1,1,2,3), "cm"))+
  theme(axis.text.y= element_text( size = 20),axis.text.x= element_text( size = 18),legend.text=element_text(size=20))



```




### Figure D2

*Mean politicalness scores for validation test for the real ads experiment*

```{r d2}

follow <- read.csv(paste0(PATH,'Data/Follow up/polad.csv'))

follow$political_affiliat[follow$political_affiliat==""] <-NA
follow$political_affiliat[follow$political_affiliat=="Other:"] <-"Independent"
follow$political_affiliat = factor(follow$political_affiliat, levels=(c("Strong Democrat","Weak Democrat","Independent","Weak Republican","Strong Republican")))



ads2 <- follow[,c(33,30,27,29,42,43,36,37,34,35,40,41,31,32,38,39)]
for(i in 1:ncol(ads2)){
  for(j in  1:nrow(ads2)){
    ads2[j,i][ads[j,i]==""] <- NA}
  ads2[,i] <- factor(ads2[,i], levels=(c("Not at all political","Slightly political","Somewhat political","Very political","Extremely political")))
}

weights <-data.frame(matrix(ncol=4,nrow=16,NA))
colnames(weights) <- c('Estimate','Lower 95 CI','Upper 95 CI','Standard Err.')

for(i in 1:ncol(ads2)){
  weights[i,] <- ci(as.numeric(ads2[,i]), na.rm=T)
}

weights$`Political Content` <- rep(c('Strong','Weak'),8)
weights$Ad <- rep(c("Biden","Trump","Power", "Sierra","MSC",
                    'Patagonia',"Exxon","Colgate"),each =2)
weights$Ad = factor(weights$Ad, levels=rev(c("Biden","Trump","Power", "Sierra",'Patagonia',"MSC","Exxon","Colgate")))

realAds <- weights

f2 <- ggplot(weights, aes(y = Estimate, x = Ad, colour= `Political Content`   ))+
  geom_pointrange(aes(y = Estimate,ymin = `Lower 95 CI`, 
                      ymax = `Upper 95 CI`),
                  size = 1) +
  coord_flip() + 
  ylim(1,4)+  xlab("")+ 
  ylab("")+ 
  scale_y_continuous(limits = c(1,5),
                     labels=c('Not \n political \n (1)',
                              '',
                              ' \n\n (3)',
                              '',
                              'Extremely \n political \n (5)'))+ 
  theme(panel.spacing.x = unit(27, "mm"),
        axis.text.x=element_text(angle=0,
                                 hjust=0.5,vjust=.5))+
  theme(axis.text.y = element_text(face=rev(c("bold","bold",
                                              "italic","italic",
                                              'plain','plain','plain','plain'))))

f2+theme(text=element_text(size=20)) + scale_color_manual(values =  c("sienna4", 'navajowhite3'), name = "")+ geom_hline( yintercept = 0, colour = "gray", size = 1, lty= 'dashed')+
  theme(plot.margin = unit(c(1,1,2,3), "cm"))+
  theme(axis.text.y= element_text( size = 20),axis.text.x= element_text( size = 18),legend.text=element_text(size=20))



```


## Additional Results for Conjoint experiment

### Table f1.

*Effects of advertisement's attributes on perception of ad's politicalness*

```{r tf1,out.width='75%'}


#cj-unconditional
unconditional <- amce(dv1 ~ image  + messageOrient + messageStrength + sourceOrient + sourceType  , respondent.id= 'CaseId', cluster=TRUE,  weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)
summary(unconditional)

summary(cj)


```


### Table F2. 

*Effect of pro-development message and source on perception of ad’s politicalness, conditioned on pro-development prior orientation, interactions are displayed respectively*

```{r tf2,out.width='75%'}

#cj-interact-orient-full
sourcexprior <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + priors + sourceOrient*priors, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'priors', na.ignore=T)
summary(sourcexprior)

mesxprior <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + priors + messageOrient*priors, cluster=TRUE, respondent.id="CaseId", respondent.varying= 'priors', weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)
summary(mesxprior)

table(is.na(cj$priors))

str(mesxprior)


```


### Table F3. 

*Effect of pro-development message and source on perception of ad’s politicalness conditioned on pro-development prior orientation, both interactions included simultaneously*
```{r tf3,out.width='75%'}

#cj-interact-messxpriorxsource
sourcexpriorxmess <- amce(dv1 ~   image  + messageOrient + messageStrength + sourceOrient + sourceType  + priors +  messageOrient*priors + sourceOrient*priors, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'priors', na.ignore=T)

summary(sourcexpriorxmess)




```



### Table F4 

*Effect of pro-development message and source on perception of ad’s politicalness conditioned on party ID*

```{r tf4,out.width='75%'}

####################################################
#Message and party-id
####################################################
mesxpid <- amce(dv1 ~ image  + messageOrient + messageStrength + sourceOrient + sourceType   +  pid + messageOrient*pid, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= bases, respondent.varying = 'pid', na.ignore=T)
summary(mesxpid)

####################################################
#Source and party-id
####################################################

sourcexpid <- amce(dv1 ~ image  + messageOrient + messageStrength + sourceOrient + sourceType   +  pid + sourceOrient*pid, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= bases, respondent.varying = 'pid', na.ignore=T)
summary(sourcexpid)
```

### Table F5 

*Effect of pro-development message and source on perception of ad’s politicalness conditioned on gender*

```{r tf5,out.width='75%'}

####################################################
#Message and gender
####################################################

mesxGENDER <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + GENDER + messageOrient*GENDER, cluster=TRUE, respondent.id="CaseId", respondent.varying= 'GENDER', weights ='WEIGHT', data=cj, baseline= baselines, na.ignore=T)
summary(mesxGENDER)

####################################################
#Source and gender
####################################################
sourcexGENDER <- amce(dv1 ~  image  + messageOrient + messageStrength + sourceOrient + sourceType   + GENDER + sourceOrient*GENDER, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'GENDER', na.ignore=T)
summary(sourcexGENDER)


####################################################
#Source, Message, and gender
####################################################
sourcexGENDERxmess <- amce(dv1 ~   image  + messageOrient + messageStrength + sourceOrient + sourceType  + GENDER +  messageOrient*GENDER + sourceOrient*GENDER, cluster=TRUE, respondent.id="CaseId", weights ='WEIGHT', data=cj, baseline= baselines, respondent.varying= 'GENDER', na.ignore=T)

summary(sourcexGENDERxmess)


```


## Additional results for real ads experiment

### Figure G1. and Figure G2. 

*Summary statistics for the Ads.*
```{r fg1fg2,out.width='75%', fig.align='center'}

############################################################################
# descriptive statistics
#############################################################################

experiment <-c('POLADSTRUMP1S4', 'POLADSTRUMP2S4', 'POLADSBIDEN1S4', 'POLADSBIDEN2S4','POLADSPOWER1S4','POLADSPOWER2S4','POLADSSIERRA1S4','POLADSSIERRA2S4', 'POLADSEXXON1S4', 'POLADSEXXON2S4', 'POLADSPATAGONIA1S4', 'POLADSPATAGONIA2S4','POLADSCOLGATE1S4','POLADSCOLGATE2S4','POLADSMSC1S4','POLADSMSC2S4')

des <-  as.data.frame(matrix(nrow=80))
colnames(des)<-'freq'
freq <- c()
for(i in 1:16){
  freq <-  c(freq,(table(pooled$estimate[pooled$experiment==experiment[i]])))
}


for(i in 1:16){
  print( experiment[i])
  print(table(pooled$estimate[pooled$experiment==experiment[i]]))
}
des$freq <- freq
des$exp <- rep(experiment,each=5)
des$name <-rep(c('Trump','Biden','Power','Sierra','Exxon','Patagonia','Colgate', 'MSC'),each=10)
des$lvl <- rep(c('High','Low'),each=5,len=80)
des$rating <- rep(1:5,16)

des1<- des[c(1:40),]
des2<- des[c(41:80),]

des1$name = factor(des1$name, levels=(c("Biden","Trump",
                                       "Power", "Sierra")))
des2$name = factor(des2$name, levels=(c("Exxon","MSC",'Patagonia',"Colgate")))

des1$lvl = factor(des1$lvl, levels=(c("Low",
                                        "High")))
des2$lvl = factor(des2$lvl, levels=(c("Low",
                                      "High")))

# Distributions
des1$lvl <- ifelse(des1$lvl == 'High','Strong','Weak')
des2$lvl <- ifelse(des2$lvl == 'High','Strong','Weak')
des1$lvl <- factor(des1$lvl , levels = c('Weak','Strong'))
des2$lvl <- factor(des2$lvl , levels = c('Weak','Strong'))

#Plot full response distributions of politicalness for strong and weak-message ads from candidates and organizations in the real ads experiment

ggplot(data = des1, aes(rating, freq, fill=name)) +
  geom_bar(stat='identity') +
  labs(y = "Frequency", x = "Rating") + 
  facet_grid(name ~ lvl) +
  theme(strip.background = element_rect(fill="GREY87"),
        strip.text = element_text(colour = 'GREY32'),
        legend.position = "none",
        text = element_text(size = 25),
        axis.title.y = element_text(angle = 0, vjust = 0.5), # Fix y-axis label orientation
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("darkseagreen4", "lightpink3", "sienna4", "navajowhite3"))

#Plot full response distributions for companies

ggplot(data = des2, aes(rating, freq, fill = as.factor(name))) +
  geom_bar(stat = 'identity') +
  labs(y = "Frequency", x = "Rating") + 
  facet_grid(name ~ lvl) +
  theme(panel.grid.minor = element_blank(),
        panel.grid.major = element_line(colour = "grey87", size = 0.5),
        strip.background = element_rect(fill="GREY87"),
        strip.text = element_text(colour = 'GREY32'),
        legend.position = "none",
        text = element_text(size = 25),
        axis.title.y = element_text(angle = 0, vjust = 0.5), # Fix y-axis label orientation
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("darkseagreen4", "lightpink3", "sienna4", "navajowhite3"))
```

### Figure F3 *Disaggregated average perceived politicalness of political ads by source, message strength, from NORC1 and NORC2*

```{r ff3,out.width='75%', fig.align='center'}
dat <- dat[,-1]
datb <- datb[,-1]
datb$Ad = factor(datb$Ad, levels=rev(c("Biden","Trump",
                                       "Power", "Sierra",'Patagonia',"Exxon","MSC", "Colgate")))
dat$Ad = factor(dat$Ad, levels=rev(c("Biden","Trump",
                                     "Power", "Sierra",'Patagonia',"Exxon","MSC",  "Colgate")))

colnames(dat) <- c('Mean','Lower 95 CI','Upper 95 CI','Standard Err.','Iteration', 'Political level', 'Advertisement')
colnames(datb) <- c('Mean','Lower 95 CI','Upper 95 CI','Standard Err.','Iteration',  'Political level', 'Advertisement')

colnames(dat)[6] <-'Political Content'
colnames(datb)[6] <-'Political Content'


d <- rbind(dat, datb)

d['Iter'] <- paste(d$`Political Content`,d$Iteration,sep=', ')
d$Iter<- factor(d$Iter, levels= c('Strong, Original','Weak, Original','Strong, Correction','Weak, Correction'))

f4 <- ggplot(d, aes(y = Mean, x = Advertisement , colour=Iter,shape = Iter ))+
  geom_pointrange(aes(y = Mean,ymin = `Lower 95 CI`, 
                      ymax = `Upper 95 CI`),
                  position = position_dodge(width = -.6),
                  size = .8) +
  coord_flip() + 
  ylim(1,4)+  xlab("")+ 
  ylab("")+ 
  scale_y_continuous(limits = c(1,5),
                     labels=c('Not \n political \n (1)',
                              '',
                              '3',
                              '',
                              'Extremely \n political \n (5)'))+ 
  theme(panel.spacing.x = unit(27, "mm"),
        axis.text.x=element_text(angle=15,
                                 hjust=0.5,vjust=.5))+
  theme(axis.text.y = element_text(face=rev(c("bold","bold",
                                              "italic","italic",
                                              'plain','plain','plain','plain'))))+
  theme_minimal() +  # Set the plot theme to minimal
  theme(
    axis.text.x = element_text(angle = 15, hjust = 0.5, vjust = 0.5),
    axis.text.y = element_text(
      face = rev(c("bold", "bold", "italic", "italic", 'plain', 'plain', 'plain', 'plain')),
      size = 20,
      hjust = 0,  # Align y-axis ticks to the left
      color = "black"  # Set the color of y-axis ticks to black
    ),
    axis.text = element_text(color = "black"),
    legend.text = element_text(size = 20, color = "black", face = "bold")  # Set the legend text to bold
  )

f4+theme(text=element_text(size=20))  +
  scale_colour_manual(name = "",
                     labels = c( "Strong, NORC1", "Weak, NORC1","Strong, NORC2", "Weak, NORC2"),
                     values = c("sienna4", 'navajowhite3',"sienna4", 'navajowhite3')) + 
  scale_shape_manual(name = "", 
                     labels = c( "Strong, NORC1", "Weak, NORC1","Strong, NORC2", "Weak, NORC2"),
                     values = c(19, 19, 17, 17))+
  geom_hline( yintercept = 0, colour = "gray", size = 1, lty= 'dashed')+
  theme(plot.margin = unit(c(1,1,1,3), "cm"))+
  theme(axis.text.y= element_text( size = 20),axis.text.x= element_text( size = 18),legend.text=element_text(size=20))


# #May add these grids and labels in plot view if you change your plot region to 12x9 
# 
# grid.locator(unit="native")
# grid.brackets(100, 125,  100, 65, type=4, ticks=NA,h =.05)
# grid.brackets(100, 245,  100, 185, type=4, ticks=NA,h =.05)
# grid.brackets(100, 365,  100, 305, type=4,ticks=NA,h =.008, col ='gray')
# grid.brackets(100, 485,  100, 425, type=4,ticks=NA,h =.008, col ='gray')
# grid.brackets(100, 488,  100, 302, type=4,ticks=NA,h =.05)
# 
# 
# grid.text(x=unit(50, 'native'), y=unit(550, 'native'), label='Politicians', rot=90,
#           gp = gpar(fontsize = 18, fontface = "bold") )
# grid.text(x=unit(50, 'native'), y=unit(420, 'native'), label='Organizations', rot=90,
#           gp = gpar(fontsize = 18, fontface = "italic") )
# grid.text(x=unit(50, 'native'), y=unit(250, 'native'), label='Companies', rot=90,
#           gp = gpar(fontsize = 18) )
# grid.text(x=unit(85, 'native'), y=unit(315, 'native'), label='Political', rot=90,
#           gp = gpar(fontsize = 13))
# 
# grid.text(x=unit(85, 'native'), y=unit(202, 'native'), label='Non-political', rot=90,
#           gp = gpar(fontsize = 13))


```


### Table G1. 

*Summary statistics for the real ads experiment by condition2*
```{r}

pooled %>% group_by(experiment) %>% 
    summarise(mean_pol=mean(estimate,na.rm=TRUE),
              se=sd(estimate,na.rm=TRUE),
              )

```


### Table G2.

*Effect of exposure to ads with strong or weak message strength on perceived politicalness of ad*

```{r tg2, out.width='75%'}


trump <- lm_robust(estimate ~ Trump, data =subset(pooled,pooled$experiment=='POLADSTRUMP1S4'|pooled$experiment == 'POLADSTRUMP2S4') , weights = WEIGHT ,cluster=CaseId)


biden  <- lm_robust(estimate ~ Biden, data = subset(pooled,pooled$experiment=='POLADSBIDEN1S4'|pooled$experiment == 'POLADSBIDEN2S4'), weights = WEIGHT )

patagonia  <- lm_robust(estimate ~ Patagonia, data =subset(pooled,pooled$experiment=='POLADSPATAGONIA1S4'|pooled$experiment == 'POLADSPATAGONIA2S4'), weights = WEIGHT )

exxon <- lm_robust(estimate ~ Exxon, data = subset(pooled,pooled$experiment=='POLADSEXXON1S4'|pooled$experiment == 'POLADSEXXON2S4'), weights = WEIGHT )

power  <- lm_robust(estimate ~ Power, data = subset(pooled,pooled$experiment=='POLADSPOWER1S4'|pooled$experiment == 'POLADSPOWER2S4'), weights = WEIGHT )


sierra <- lm_robust(estimate ~Sierra, data = subset(pooled,pooled$experiment=='POLADSSIERRA1S4'|pooled$experiment == 'POLADSSIERRA2S4'), weights = WEIGHT )


colgate <- lm_robust(estimate ~ Colgate, data = subset(pooled,pooled$experiment=='POLADSCOLGATE1S4'|pooled$experiment == 'POLADSCOLGATE2S4'), weights = WEIGHT )


msc <- lm_robust(estimate ~ MSC, data = subset(pooled,pooled$experiment=='POLADSMSC1S4'|pooled$experiment == 'POLADSMSC2S4'), weights = WEIGHT )
screenreg(list(biden, trump, power, sierra, exxon, patagonia, msc, colgate),include.ci=F)


```


### Table G3.

*Effect of exposure to ads with strong or weak message strength on perceived politicalness of ad, by pid*
```{r tg3,out.width='75%'}

#Pooled real ad experiments

pooled$political <- NA

for(i in 1:nrow(pooled)){
  if(pooled$experiment[i] == 'POLADSTRUMP1S4'|pooled$experiment[i] =="POLADSTRUMP2S4"){
    pooled$political[i] <- pooled$Trump[i]
  }  else if(pooled$experiment[i] == 'POLADSBIDEN1S4' | pooled$experiment[i] ==  "POLADSBIDEN2S4"){
    pooled$political[i] <- pooled$Biden[i]
  } else if(pooled$experiment[i] == 'POLADSEXXON1S4'| pooled$experiment[i] == "POLADSEXXON2S4" ){
    pooled$political[i] <- pooled$Exxon[i]
  } else if(pooled$experiment[i] == 'POLADSPATAGONIA1S4'| pooled$experiment[i] == "POLADSPATAGONIA2S4" ){
    pooled$political[i] <- pooled$Patagonia[i]
  } else if(pooled$experiment[i] == 'POLADSPOWER1S4'| pooled$experiment[i] == "POLADSPOWER2S4" ){
    pooled$political[i] <- pooled$Power[i]
  } else if(pooled$experiment[i] == 'POLADSSIERRA1S4'| pooled$experiment[i] == "POLADSSIERRA2S4" ){
    pooled$political[i] <- pooled$Sierra[i]
  } #else if(pooled$experiment[i] == 'POLADSCOLGATE1S4'| pooled$experiment[i] == "POLADSCOLGATE2S4"){
    #pooled$political[i] <- pooled$Colgate[i]
  #} else if(pooled$experiment[i] == 'POLADSMSC1S4'| pooled$experiment[i] == 'POLADSMSC2S4' ){
   # pooled$political[i] <- pooled$MSC[i]
 # }
}

ra<- pooled


ra$candidate <- NA
for(i in 1:nrow(ra)){
  if(ra$experiment[i] == "POLADSTRUMP1S4"|ra$experiment[i] =="POLADSTRUMP2S4"|
     ra$experiment[i] == "POLADSBIDEN1S4"|ra$experiment[i] =="POLADSBIDEN2S4"){
    ra$candidate[i] <- 1
  } else{ ra$candidate[i] <-0}
}


ra$organization <- NA
for(i in 1:nrow(ra)){
  if(ra$experiment[i] == "POLADSPOWER1S4"|ra$experiment[i] =="POLADSPOWER2S4" |
     ra$experiment[i] == "POLADSSIERRA1S4"|ra$experiment[i] =="POLADSSIERRA2S4"){
    ra$organization[i] <- 1
  } else{ ra$organization[i] <-0}
}

ra$company <- NA
for(i in 1:nrow(ra)){
  if(ra$experiment[i] == "POLADSEXXON1S4"|ra$experiment[i] =="POLADSEXXON2S4"|
     ra$experiment[i] == "POLADSPATAGONIA1S4"|ra$experiment[i] =="POLADSPATAGONIA2S4"){ 
       #|
    # ra$experiment[i] == "POLADSCOLGATE1S4"|ra$experiment[i] =="POLADSCOLGATE2S4"|
    # ra$experiment[i] == "POLADSMSC1S4"|ra$experiment[i] =="POLADSMSC2S4"){
    ra$company[i] <- 1
  } else{ ra$company[i] <-0}
  
}

ra$np_company <- NA
for(i in 1:nrow(ra)){
  if(
    ra$experiment[i] == "POLADSCOLGATE1S4"|ra$experiment[i] =="POLADSCOLGATE2S4"|
   ra$experiment[i] == "POLADSMSC1S4"|ra$experiment[i] =="POLADSMSC2S4"){
    ra$np_company[i] <- 1
  } else{ ra$np_company[i] <-0}
  
}

ra$pol <- ifelse(ra$political== 1,'High','Low')
ra$pol <- factor(ra$pol, levels = c('Low','High'))

ra$sourceOrient <- NA
for(i in 1:nrow(ra)){
  if(ra$experiment[i] == "POLADSEXXON1S4" | 
     ra$experiment[i] == "POLADSEXXON2S4" |
    # ra$experiment[i] == "POLADSMSC1S4" |
    # ra$experiment[i] == "POLADSMSC2S4" |
     ra$experiment[i] == "POLADSTRUMP1S4" |
     ra$experiment[i] == "POLADSTRUMP2S4" | 
     ra$experiment[i] == "POLADSPOWER1S4" | 
     ra$experiment[i] == "POLADSPOWER2S4" ){
    ra$sourceOrient[i] <- 1
  } else{ ra$sourceOrient[i] <-0}
}
ra$pid <- factor(ra$pid, levels = c('Democrat','Republican'))
ra$orientation<- factor(ra$orientation, levels = c('Pro-environment','Pro-development'))

ra$sourceOrient <- ifelse(ra$sourceOrient== 1,'Pro-development','Pro-environment')
ra$sourceOrient<- factor(ra$sourceOrient, levels = c('Pro-environment','Pro-development'))

```


```{r tf3_cont,out.width='75%'}
trump1 <- lm_robust(estimate ~ Trump+ pid, data =subset(ra,ra$experiment=='POLADSTRUMP1S4'|ra$experiment == 'POLADSTRUMP2S4') , weights = WEIGHT ,cluster=CaseId)


biden1  <- lm_robust(estimate ~ Biden+ pid, data = subset(ra,ra$experiment=='POLADSBIDEN1S4'|ra$experiment == 'POLADSBIDEN2S4'), weights = WEIGHT )

patagonia1  <- lm_robust(estimate ~ Patagonia+ pid, data =subset(ra,ra$experiment=='POLADSPATAGONIA1S4'|ra$ experiment == 'POLADSPATAGONIA2S4'), weights = WEIGHT )

exxon1 <- lm_robust(estimate ~ Exxon+ pid, data = subset(ra,ra$experiment=='POLADSEXXON1S4'|ra$experiment == 'POLADSEXXON2S4'), weights = WEIGHT )

power1  <- lm_robust(estimate ~ Power+ pid, data = subset(ra,ra$experiment=='POLADSPOWER1S4'|ra$experiment == 'POLADSPOWER2S4'), weights = WEIGHT )


sierra1 <- lm_robust(estimate ~Sierra+ pid, data = subset(ra,ra$experiment=='POLADSSIERRA1S4'|ra$experiment == 'POLADSSIERRA2S4'), weights = WEIGHT )


colgate1 <- lm_robust(estimate ~ Colgate+ pid, data = subset(ra,ra$experiment=='POLADSCOLGATE1S4'|ra$experiment == 'POLADSCOLGATE2S4'), weights = WEIGHT )


msc1 <- lm_robust(estimate ~ MSC+ pid, data = subset(ra,ra$experiment=='POLADSMSC1S4'|ra$experiment == 'POLADSMSC2S4'), weights = WEIGHT )

screenreg(list(biden1, trump1, power1, sierra1, exxon1, patagonia1
               , msc1, colgate1),include.ci=F)

```



### Table G4 

*Effect of exposure to ads on perceived politicalness of ad, by gender*
```{r tg4,out.width='75%'}

#Pooled real ad experiments

pooled_gender$political <- NA
# pooled_gender$political <- pooled$political

for(i in 1:nrow(pooled_gender)){
  if(pooled_gender$experiment[i] == 'POLADSTRUMP1S4'|pooled_gender$experiment[i] =="POLADSTRUMP2S4"){
    pooled_gender$political[i] <- pooled_gender$Trump[i]
  }  else if(pooled_gender$experiment[i] == 'POLADSBIDEN1S4' | pooled_gender$experiment[i] ==  "POLADSBIDEN2S4"){
    pooled_gender$political[i] <- pooled_gender$Biden[i]
  } else if(pooled_gender$experiment[i] == 'POLADSEXXON1S4'| pooled_gender$experiment[i] == "POLADSEXXON2S4" ){
    pooled_gender$political[i] <- pooled_gender$Exxon[i]
  } else if(pooled_gender$experiment[i] == 'POLADSPATAGONIA1S4'| pooled_gender$experiment[i] == "POLADSPATAGONIA2S4" ){
    pooled_gender$political[i] <- pooled_gender$Patagonia[i]
  } else if(pooled_gender$experiment[i] == 'POLADSPOWER1S4'| pooled_gender$experiment[i] == "POLADSPOWER2S4" ){
    pooled_gender$political[i] <- pooled_gender$Power[i]
  } else if(pooled_gender$experiment[i] == 'POLADSSIERRA1S4'| pooled_gender$experiment[i] == "POLADSSIERRA2S4" ){
    pooled_gender$political[i] <- pooled_gender$Sierra[i]
  }
}

ra_gender <- pooled_gender

ra_gender$gender[ra_gender$gender==1]<-'Male'
ra_gender$gender[ra_gender$gender==2]<-'Female'
ra_gender$gender<-factor(ra_gender$gender,levels = c('Male','Female'))

ra_gender$candidate <- NA
ra_gender$organization <- NA 
ra_gender$company <- NA

ra_gender$candidate<-ifelse(ra_gender$experiment %in% c('POLADSTRUMP1S4','POLADSBIDEN1S4','POLADSTRUMP2S4','POLADSBIDEN2S4'), 1, 0)

ra_gender$organization<-ifelse(ra_gender$experiment %in% c("POLADSPOWER1S4","POLADSPOWER2S4" , "POLADSSIERRA1S4","POLADSSIERRA2S4"), 1, 0)

ra_gender$company<-ifelse(ra_gender$experiment %in% c("POLADSEXXON1S4","POLADSEXXON2S4","POLADSPATAGONIA1S4","POLADSPATAGONIA2S4"), 1, 0)



ra_gender$pol <- ifelse(ra_gender$political== 1,'High','Low')
ra_gender$pol <- factor(ra_gender$pol, levels = c('Low','High'))

# ra_gender$sourceOrient <- ra$sourceOrient 
ra_gender$sourceOrient <- NA
for(i in 1:nrow(ra_gender)){
  if(ra_gender$experiment[i] == "POLADSEXXON1S4" |
     ra_gender$experiment[i] == "POLADSEXXON2S4" |
    # ra_gender$experiment[i] == "POLADSMSC1S4" |
    # ra_gender$experiment[i] == "POLADSMSC2S4" |
     ra_gender$experiment[i] == "POLADSTRUMP1S4" |
     ra_gender$experiment[i] == "POLADSTRUMP2S4" |
     ra_gender$experiment[i] == "POLADSPOWER1S4" |
     ra_gender$experiment[i] == "POLADSPOWER2S4" ){
    ra_gender$sourceOrient[i] <- 1
  } else{ ra_gender$sourceOrient[i] <-0}
}
ra_gender$pid <- factor(ra_gender$pid, levels = c('Democrat','Republican'))
ra_gender$orientation<- factor(ra_gender$orientation, levels = c('Pro-environment','Pro-development'))
ra_gender$sourceOrient <- ifelse(ra_gender$sourceOrient== 1,'Pro-development','Pro-environment')
ra_gender$sourceOrient<- factor(ra_gender$sourceOrient, levels = c('Pro-environment','Pro-development'))

```


```{r tg5_cont,out.width='75%'}
trump1 <- lm_robust(estimate ~ Trump+ gender , data =subset(ra_gender,ra_gender$experiment=='POLADSTRUMP1S4'|ra_gender$experiment == 'POLADSTRUMP2S4') , weights = WEIGHT ,cluster=CaseId)


biden1  <- lm_robust(estimate ~ Biden+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSBIDEN1S4'|ra_gender$experiment == 'POLADSBIDEN2S4'), weights = WEIGHT )

patagonia1  <- lm_robust(estimate ~ Patagonia+ gender, data =subset(ra_gender,ra_gender$experiment=='POLADSPATAGONIA1S4'|ra_gender$ experiment == 'POLADSPATAGONIA2S4'), weights = WEIGHT )

exxon1 <- lm_robust(estimate ~ Exxon+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSEXXON1S4'|ra_gender$experiment == 'POLADSEXXON2S4'), weights = WEIGHT )

power1  <- lm_robust(estimate ~ Power+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSPOWER1S4'|ra_gender$experiment == 'POLADSPOWER2S4'), weights = WEIGHT )


sierra1 <- lm_robust(estimate ~Sierra+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSSIERRA1S4'|ra_gender$experiment == 'POLADSSIERRA2S4'), weights = WEIGHT )


colgate1 <- lm_robust(estimate ~ Colgate+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSCOLGATE1S4'|ra_gender$experiment == 'POLADSCOLGATE2S4'), weights = WEIGHT )


msc1 <- lm_robust(estimate ~ MSC+ gender, data = subset(ra_gender,ra_gender$experiment=='POLADSMSC1S4'|ra_gender$experiment == 'POLADSMSC2S4'), weights = WEIGHT )

screenreg(list(biden1, trump1, power1, sierra1, exxon1, patagonia1
               , msc1, colgate1),include.ci=F)

```


### Table G5. 

*One‐tailed T‐Test results for differences in mean politicalness score between ad source categories*

```{r tg5,out.width='75%'}


library(dplyr)

# Subset data
candidate <- ra[ra$candidate==1, ]
advocacy <- ra[ra$organization==1, ]
p_bus <- ra[ra$company==1, ]
np_bus <- ra[ra$np_company==1, ]

#groupby
candidate_score<-candidate %>% group_by(CaseId) %>% 
    summarise(mean_pol=mean(estimate,na.rm=TRUE))
advocacy_score<-advocacy %>% group_by(CaseId) %>% 
    summarise(mean_pol=mean(estimate,na.rm=TRUE))
p_bus_score<-p_bus %>% group_by(CaseId) %>% 
    summarise(mean_pol=mean(estimate,na.rm=TRUE))
np_bus_score<-np_bus %>% group_by(CaseId) %>% 
    summarise(mean_pol=mean(estimate,na.rm=TRUE))



library(dplyr)
common_ids <- intersect(candidate_score$CaseId, advocacy_score$CaseId)
filtered_candidate <- candidate_score %>% filter(CaseId %in% common_ids)
filtered_advocacy  <- advocacy_score %>% filter(CaseId %in% common_ids)

#Biden vs. Trump

t_test_1 <- t.test(filtered_candidate$mean_pol, filtered_advocacy$mean_pol, paired = TRUE,alternative = "greater")
print(t_test_1)



#Advocacy Groups vs. Political Business
common_ids <- intersect(advocacy_score$CaseId, p_bus_score$CaseId)
filtered_advocacy <- advocacy_score[advocacy_score$CaseId %in% common_ids, ]
filtered_p_bus <- p_bus_score[p_bus_score$CaseId %in% common_ids, ]

t_test_2 <- t.test(filtered_advocacy$mean_pol,filtered_p_bus$mean_pol, paired = TRUE, alternative = "greater")
print(t_test_2)

#Political Business vs Non-political Business
common_ids <- intersect(np_bus_score$CaseId, p_bus_score$CaseId)
filtered_np_bus <- np_bus_score[np_bus_score$CaseId %in% common_ids, ]
filtered_p_bus <- p_bus_score[p_bus_score$CaseId %in% common_ids, ]
t_test_3 <- t.test(filtered_p_bus$mean_pol, filtered_np_bus$mean_pol,paired = TRUE,  alternative = "greater")
print(t_test_3)



```




### Table G6. 

*Effect of exposure to ads with strong or weak message interacted with source on perceived politicalness of ads: Pooled analysis, non-political companies excluded*

```{r tg6,out.width='75%'}

poolFit <- lm_robust(estimate ~ candidate+organization+ pol +sourceOrient, data = ra, weights = WEIGHT, clusters = CaseId, fixed_effects = ~CaseId, se_type = 'stata')

interFit <- lm_robust(estimate ~ pol*candidate+pol*organization+ sourceOrient, data = ra, weights = WEIGHT, clusters = CaseId, fixed_effects = ~CaseId, se_type = 'stata')

partyFit <- lm_robust(estimate ~ sourceOrient*pid+candidate+organization+ pol, data = ra, weights = WEIGHT, clusters = CaseId, fixed_effects = ~CaseId, se_type = 'stata')

genderFit <- lm_robust(estimate ~ sourceOrient*gender+candidate+organization+ pol, data = ra_gender, weights = WEIGHT, clusters = CaseId, fixed_effects = ~CaseId, se_type = 'stata')

screenreg(list(poolFit, interFit, partyFit,genderFit), include.ci=F,custom.model.names =  c('Model 1' ,'Model 2', 'Model 3','Model 4'))



```



